<template>
<div>
  <el-table
      :data="tableData"
      border
      style="width: 100%">
    <el-table-column
        fixed
        prop="buynumber"
        label="采购编号"
        width="150">
    </el-table-column>
    <el-table-column
        fixed
        prop="goodsname"
        label="商品名"
        width="150">
    </el-table-column>
    <el-table-column
        prop="standerd"
        label="商品规格"
        width="120">
    </el-table-column>
    <el-table-column
        prop="type"
        label="商品类型"
        width="120">
    </el-table-column>
    <el-table-column
        prop="price"
        label="建议价格"
        width="120">
    </el-table-column>
    <el-table-column
        prop="buynum"
        label="采购数量"
        width="100">
    </el-table-column>
    <el-table-column
        fixed="right"
        label="竞标"
        width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">报价</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
    <el-row>
      <el-col :span="6"><span>报价:</span></el-col>
      <el-col :span="6"><el-input v-model="offernum" placeholder="请输入报价"></el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6"><span>竞标描述:</span></el-col>
      <el-col :span="12"><el-input
          type="textarea"
          autosize
          placeholder="请输入竞标描述"
          v-model="offerinfo">
      </el-input>
      </el-col>
    </el-row>
    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="open">确定报价</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
export default {
  name: "BuyView",
  data(){
    return{
      dialogVisible:false,
      offernum:0,
      offerinfo:"",
      tableData:[],
      row:null
    }
  },
  mounted() {
    this.init()
    console.log(1)
  },
  methods:{
    handleClick(row){
     this.row=row;
     this.dialogVisible=true;
    },
    init(){
      console.log()
      this.$axios.get("/psc/buyrequest/findBuyrequest/"+sessionStorage.getItem("userNumber")+"").then(
          r=>{
            this.tableData=r.data
          }
      )
    },open(){
    this.$alert('你确定要报价嘛？', '报价信息', {
      confirmButtonText: '确定',
      callback: action => {
        this.action(action);
      }
    });
  },action(action){
      console.log(action)
     if(this.offernum!=0&&this.offerinfo!=""){
       let offer = this.row;
       let fd=new FormData();
       fd.append("buynumber",offer.buynumber)
       fd.append("offernum",this.offernum)
       fd.append("offerinfo",this.offerinfo)
       fd.append("usernumber",offer.usernumber)
       this.$axios.post("/psc/offer/accept",fd).then(
           r=>{
             if(r.data==true){
               this.$message.success("竞标报价成功")
               this.dialogVisible=false;
               this.offernum=0;
               this.offerinfo="";
               this.init();
             }else {
               this.$message.error("竞标报价失败，请重写报价")
             }
           }
       )
     }else {
       this.$message.warning("竞标报价和中标描述不能为空")
     }
    }
  }
}
</script>

<style scoped>

</style>